package com.java83.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.java83.domain.LzhServicer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.java83.service.LzhServicerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务者Controller
 * 
 * @author ruoyi
 * @date 2022-02-17
 */
@RestController
@RequestMapping("/servicer")
public class LzhServicerController extends BaseController
{
    @Autowired
    private LzhServicerService lzhServicerService;

    /**
     * 查询服务者列表
     */
    @RequiresPermissions("Servicer:servicer:list")
    @GetMapping("/list")
    public TableDataInfo list(LzhServicer lzhServicer)
    {
        startPage();
        List<LzhServicer> list = lzhServicerService.selectLzhServicerList2(lzhServicer);
        return getDataTable(list);
    }

    /**
     * 导出服务者列表
     */
    @RequiresPermissions("Servicer:servicer:export")
    @Log(title = "服务者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LzhServicer lzhServicer)
    {
        List<LzhServicer> list = lzhServicerService.selectLzhServicerList(lzhServicer);
        ExcelUtil<LzhServicer> util = new ExcelUtil<LzhServicer>(LzhServicer.class);
        util.exportExcel(response, list, "服务者数据");
    }

    /**
     * 获取服务者详细信息
     */
    @RequiresPermissions("Servicer:servicer:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lzhServicerService.selectLzhServicerById(id));
    }

    /**
     * @Author: TangShuJi
     * @Description: (Web控制层)动态获取员工名称方法
     * @Date: 2021/12/23 15:28
     * @Param: []
     * @Return: com.java83.response.AjaxResult<java.lang.String>
     **/
    @RequestMapping(value = "/getEmployeeDepartmentName", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult getEmployeeDepartmentName() {
        String name = lzhServicerService.getEmployeeDepartmentName();
        if (name != null) {
            // 添加成功
            return AjaxResult.success(name);
        }
        return null;
    }

    /**
     * 新增服务者
     */
    @RequiresPermissions("Servicer:servicer:add")
    @Log(title = "服务者", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LzhServicer lzhServicer)
    {
        return toAjax(lzhServicerService.insertLzhServicer(lzhServicer));
    }

    /**
     * 修改服务者
     */
    @RequiresPermissions("Servicer:servicer:edit")
    @Log(title = "服务者", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LzhServicer lzhServicer)
    {
        return toAjax(lzhServicerService.updateLzhServicer(lzhServicer));
    }

    /**
     * 删除服务者
     */
    @RequiresPermissions("Servicer:servicer:remove")
    @Log(title = "服务者", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lzhServicerService.deleteLzhServicerByIds(ids));
    }
}
